package com.forezp.configclient.springboot2Rabbit;

import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @version V1.0  </br>
 * @ClassName RabbitTest </br>
 * @Description TODO  </br>
 * @Author tonywang</br>
 * @DATE 11/26/2018 10:29 AM</br>
 */
@RestController
@RequestMapping("/rabbit")
public class RabbitController {
    @Autowired
    private HelloSender helloSender;
    @Autowired
    private UserSender userSender;
    @Autowired
    private TopicSender topicSender;
    @Autowired
    private FanoutSender fanoutSender;

    @Autowired
    private CallBackSender callBackSender;
    @GetMapping("/hello")
    public void hello() {
        helloSender.send("hello");
    }

    /**
     * 单生产者-多消费者
     */
    @GetMapping("/oneToMany")
    public void oneToMany() {
        for(int i=0;i<10;i++){
            helloSender.send("oneToMany:" + i);
        }
    }

    /**
     * 多生产者-多消费者
     */
    @GetMapping("/manyToMany")
    public void manyToMany() {
        for(int i=0;i<10;i++){
            helloSender.send("hellomsg:"+i);
            helloSender.send2("hellomsg:"+i);
        }
    }
    /**
     * 实体类传输测试
     */
    @GetMapping("/userTest")
    public void userTest() {
        userSender.send();
    }

    /**
     * topic exchange类型rabbitmq测试
     */
    @GetMapping("/topicTest/{msg}")
    public void topicTest(@PathVariable(required = false) String msg) {
        topicSender.send(msg);
    }

    /**
     * fanout exchange类型rabbitmq测试
     */
    @GetMapping("/fanoutTest")
    public void fanoutTest() {
        fanoutSender.send();
    }

    @GetMapping("/callback")
    public void callbak() {
        callBackSender.send();
    }
}
